﻿// ==========================================================================
// LoadingIndicator.cs
// Silverlight Shapes Library
// ==========================================================================
// Copyright (c) Silverlight Shapes Development Group
// All rights reserved.
// ==========================================================================

using System.Windows;
using System.Windows.Controls;

namespace SD.Samples.Views
{
    /// <summary>
    /// User control that renders an animation to indicating that something is loading.
    /// </summary>
    public partial class LoadingIndicator : UserControl
    {
        #region Dependency Properties

        /// <summary>
        /// Defines the <see cref="Text"/> dependency property.
        /// </summary>
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(string), typeof(LoadingIndicator), new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnTextChanged)));
        /// <summary>
        /// Gets or sets the text that is rendered at the center of the animated circle.
        /// </summary>
        /// <value>The text that is rendered at the center of the animated circle.</value>
        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        private static void OnTextChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            var owner = o as LoadingIndicator;
            if (owner != null)
            {
                owner.OnTextChanged();
            }
        }

        private void OnTextChanged()
        {
            TextBlock.Text = Text;
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="LoadingIndicator"/> class.
        /// </summary>
        public LoadingIndicator()
        {
            InitializeComponent();

            RotatingStoryboard.Begin(); 
        }

        #endregion
    }
}
